home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
A.C.E. 2
/
ACE CD 2.iso
/
FILES
/
UTILS
/
AMOSPRO5.DMS
/
in.adf
/
Quatro.AMOS
/
Quatro.amosSourceCode
< prev
next >
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
Macintosh to JP
NeXTSTEP
RISC OS/Acorn
Shift JIS
UTF-8
Wrap
AMOS Source Code
|
1992-09-30
|
28.0 KB
|
1,237 lines
' ********************************************
' *** ***
' *** Q U A T R O ***
' *** ***
' *** By Dominic Ramsey ***
' *** ***
' *** (c) 1992 Europress Software ***
' *** ***
' ********************************************
'
'
' First Dimension sone arrays, & make key variables global
'
Dim BD(9,9),BX(8),SC(2),BEST(9,9),OK(9,9),OMX(2),OMY(2)
Global MX,MY,BD(),PLYR,BX(),SC(),QUIT,NUMPLAYERS,GAMEOVER,TEMP,TEMP2
Global BEST(),OK(),LEVEL,COUNT,OMX(),OMY(),ARROW$,_FONT
Close Editor
'
'
' This is the main game loop
'
Do
TITLE
INIT
'
Repeat
WHERE
If QUIT=0
CHKMVE
Else
GAMEOVER=1
End If
' Has Gameover flag been set ?
Until GAMEOVER=1
Loop
'
' That's it
'
'
' Game Procedures
'
Procedure INIT
'
' Open game screen. Set all colours to grey
'
Unpack 7 To 0
Palette $778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778
Double Buffer : Autoback 1
'
' Clear board
'
GAMEOVER=0 : QUIT=0
For Y=1 To 8
For X=1 To 8
BD(X,Y)=0
BD(X,9)=3
BD(9,Y)=3
Next X
Next Y
'
Randomize Timer
'
' Set up a simple sound envelope
'
Set Envel 1,0 To 2,30
Set Envel 1,1 To 1,20
Set Envel 1,2 To 1,20
Set Envel 1,3 To 1,0
'
' Set a counter to zero. This will stop the computer making the same
' move more than twice. This would make the game very boring.
'
COUNT=0
'
' Place 4 Pieces in centre of board
'
BD(4,4)=1 : BD(5,5)=1
BD(4,5)=2 : BD(5,4)=2
'
For Y=4 To 5
For X=4 To 5
Paste Bob(X*20)+2,(Y*20)+2,BD(X,Y)
Next X
Next Y
Screen Copy Logic To Physic : Wait Vbl
'
' Co-ords of buttons
'
BX(1)=234 : BX(2)=236 : BX(3)=243 : BX(4)=253
'
' Set frist player to go & initial scores.
'
PLYR=1 : SC(1)=2 : SC(2)=2
'
' Reserve enough screen zones for buttons & requesters
'
Reserve Zone 6
'
' Define the four on-screen buttons.
'
Set Zone 1,228,100 To 296,114
Set Zone 2,228,118 To 296,132
Set Zone 3,228,136 To 296,150
Set Zone 4,228,154 To 296,168
'
' Get correct size font
'
Get Rom Fonts
TEMP=1
Repeat
TEMP$=Font$(TEMP)
If Instr(TEMP$," 8 ")>0
_FONT=TEMP
End If
Inc TEMP
Until TEMP$=""
'
'
' Show the board by fading to sprite palette
'
Fade 2 To -1
Wait 30
'
End Proc
Procedure WHERE
'
' This procedure decides whether it is the players turn to move, or if
' it should COMPUTE a move.
'
M:
'
' Has player selected New Game?
'
If QUIT=1
Pop Proc
End If
'
' Clear message box & display new message.
'
Ink 11 : Bar 220,178 To 303,194
Ink 14,11 : Set Font _FONT
If NUMPLAYERS=1 and PLYR=2
Text 230,190,"Thinking"
Else
Paste Bob 224,179,PLYR
Text 250,190,"To Go"
End If
'
' Show player's scores
'
Gr Writing 1 : Ink 12 : Text 265,68,Str$(SC(1))+" " : Text 265,85,Str$(SC(2))+" "
'
' Copy message and score to physical screen.
'
Screen Copy Logic To Physic : Wait Vbl
'
' Is it the computer's turn?
'
If(PLYR=2 and NUMPLAYERS=1) or NUMPLAYERS=0
' Yes it is ....
COMPUTE
Else
' No it's not ....
'
' Wait for a valid move
'
Repeat
MK=0 : While MK=0
MK=Mouse Key : MZ=Mouse Zone
Wend
'
' Check if one of the four buttons has been pressed.
'
If MZ>0 and MZ<5 : BUTTONS : Goto M : End If
'
' If not, find co-oridinates of player's move
'
MY=Y Screen(Y Mouse)-21 : YS=MY
MX=X Screen(X Mouse)-21 : XS=MX
'
' Has player clicked outside board area?
'
Until(MY<173) and(MX<173)
'
'
' Find the square where player clicked.
'
MX=(MX/20)+1
MY=(MY/20)+1
If XS<0 : MX=0 : End If
If YS<0 : MY=0 : End If
End If
'
'
'
'
End Proc
Procedure CHKMVE
'
' Sound Effect
'
Play 3,35+(PLYR*5),5
'
' Check for illegal move.
'
' Slide a row
'
DEPRESS_SLIDERS
'
'
If MX=0 or MX=9
If MY>0 and MY<9
HSLIDE : Goto ND
Else
Goto N
End If
End If
'
' Slide a column
'
If MY=0 or MY=9
If MX>0 and MX<9
VSLIDE : Goto ND
Else
Goto N
End If
End If
'
'
If BD(MX,MY)>0 Then Goto ND
'
' Check above, below, left & right of selected move to check it is
' valid. The variable POSMV will be set to 1 if the move is legal.
'
POSMV=0
'
CHU:
If MY=1 Then Goto CHD
If BD(MX,MY-1)=PLYR Then POSMV=1
'
CHD:
If MY=8 Then Goto CHL
If BD(MX,MY+1)=PLYR Then POSMV=1
'
CHL:
If MX=1 Then Goto CHR
If BD(MX-1,MY)=PLYR Then POSMV=1
'
CHR:
If MX=8 Then Goto N
If BD(MX+1,MY)=PLYR Then POSMV=1
'
N:
'
' Is move Invalid?
'
If POSMV=0 Then INVALID : Goto ND
'
' All checks complete, move is valid. Paste players piece onto board.
'
Paste Bob(MX*20)+2,(MY*20)+2,PLYR : Wait Vbl
'
' Update board array
'
BD(MX,MY)=PLYR
'
' Increase player's score
'
Inc SC(PLYR)
'
' Change player
'
If PLYR=1 Then PLYR=2 Else PLYR=1
'
ND:
'
' If computer has moved, move pointer back to mouse position.
'
If(NUMPLAYERS=1 and PLYR=1) or NUMPLAYERS=0
Wait 10
Amal 1,"Let R0=XM-RA ; Let R1= YM-RB ; Move R0,R1,20 ;"
Amal On 1
End If
'
' Check board for a 4 square. If found, remove pieces from the board.
'
For TEMP=1 To 7
For TEMP2=1 To 7
For CHECK=1 To 2
If BD(TEMP,TEMP2)=CHECK and BD(TEMP+1,TEMP2)=CHECK and BD(TEMP,TEMP2+1)=CHECK and BD(TEMP+1,TEMP2+1)=CHECK
' Play a sound effect
For MUS=24 To 48 : Play 12,MUS,1 : Next
' Remove pieces from board
Paste Bob TEMP*20,TEMP2*20,10 : Paste Bob(TEMP+1)*20,TEMP2*20,10
Paste Bob TEMP*20,(TEMP2+1)*20,10 : Paste Bob(TEMP+1)*20,(TEMP2+1)*20,10
' Update board array
BD(TEMP,TEMP2)=0 : BD(TEMP+1,TEMP2)=0 : BD(TEMP,TEMP2+1)=0 : BD(TEMP+1,TEMP2+1)=0
' Decrease player's score
Add SC(CHECK),-4
End If
Next CHECK
Next TEMP2
Next TEMP
'
' Reset pointer to move with mouse
'
Wait 20
Amal 1,ARROW$
Amal On 1
'
' Check for a winner
'
CHECKWINNER
'
End Proc
Procedure BUTTONS
' Quatro jumps to this procedure when one of the buttons on the right
' hand panel is pressed.
'
' Play a note
'
Play 30,0
'
' Find which button was pressed.
MZ=Mouse Zone
'
' Get button as a compacted block.
'
Get Cblock 1,228,81+(19*MZ),76,15
'
' Replace button with depressed version stored in the Bob bank.
'
' First erase the background
Ink 11
Bar 230,82+(19*MZ) To 294,93+(19*MZ)
Paste Bob BX(MZ),82+(19*MZ),MZ+4
'
' Copy to physical screen.
'
Screen Copy Logic To Physic : Wait Vbl
'
' Wait for player to let go of left mouse button.
'
While Mouse Key=1 : Wend
'
' Wait, then replace with original image
'
Wait 10
Put Cblock 1 : Del Cblock 1
Screen Copy Logic To Physic : Wait Vbl
'
' Now take appropriate action
'
If MZ=4 Then Edit
On MZ Proc INST,NW_GAME,CREDITS
'
End Proc
Procedure CHK_BUTTONS
'
' Simple button checking routine for detecting button presses while
' computer is `thinking'.
'
If Mouse Key=1
If Mouse Zone>0 and Mouse Zone<5
BUTTONS
End If
End If
End Proc
Procedure INVALID
Bell
Get Cblock 1,99,69,220,130
Ink 8,
Bar 100,70 To 219,129
Ink 1,
Box 100,70 To 219,129
Ink 14,
Box 101,71 To 218,128
Ink 1,8 : Set Font _FONT
Text 130,85,"Invalid"
Text 135,95," Move"
Ink 12,8
Text 128,110,"Click To"
Text 128,120,"Continue"
Screen Copy Logic To Physic
While Mouse Key<>1
Wend
Put Cblock 1
Screen Copy Logic To Physic
Wait Vbl
End Proc
Procedure HSLIDE
If PLYR=1 Then PLYR=2 Else PLYR=1
Screen Open 1,210,20,16,Lowres : Flash Off : Get Palette 0
Screen Hide 1
If MX=0
Screen Copy 0,20,(MY*20),40,(MY*20)+20 To 1,160,0
Screen Copy 0,20,MY*20,180,MY*20+20 To 1,0,0
For X=1 To 20
Play 3,X/2+10,0
Screen Copy 1,X,0,160+X,20 To 0,20,MY*20
Screen Swap : Wait Vbl
Next
TMP=BD(1,MY)
For A=2 To 8
BD(A-1,MY)=BD(A,MY)
Next
BD(8,MY)=TMP
Else
Screen Copy 0,160,(MY*20),180,(MY*20)+20 To 1,0,0
Screen Copy 0,20,MY*20,180,MY*20+20 To 1,20,0
For X=20 To 0 Step -1
Play 3,X/2+11,0
Screen Copy 1,X,0,160+X,20 To 0,20,MY*20
Screen Swap : Wait Vbl
Next X
TMP=BD(8,MY)
For A=7 To 1 Step -1
BD(A+1,MY)=BD(A,MY)
Next A
BD(1,MY)=TMP
End If
Screen Copy Physic(0) To Logic(0)
Screen Close 1
Clip
End Proc
Procedure VSLIDE
If PLYR=1 Then PLYR=2 Else PLYR=1
Screen Open 1,100,200,16,Lowres : Flash Off
Screen Hide 1
Screen 0
If MY=0
Screen Copy 0,MX*20,20,MX*20+20,200 To 1,0,0
Screen Copy 0,MX*20,20,MX*20+20,40 To 1,0,160
For Y=1 To 20
Play 3,Y/2+10,0
Screen Copy 1,0,Y,20,160+Y To 0,MX*20,20
Screen Swap : Wait Vbl
Next
TMP=BD(MX,1)
For A=2 To 8
BD(MX,A-1)=BD(MX,A)
Next
BD(MX,8)=TMP
Else
Screen Copy 0,MX*20,20,MX*20+20,200 To 1,0,20
Screen Copy 0,MX*20,160,MX*20+20,180 To 1,0,0
For Y=20 To 0 Step -1
Play 3,Y/2+11,0
Screen Copy 1,0,Y,20,160+Y To 0,MX*20,20
Screen Swap : Wait Vbl
Next
TMP=BD(MX,8)
For A=7 To 1 Step -1
BD(MX,A+1)=BD(MX,A)
Next A
BD(MX,1)=TMP
End If
Screen Copy Physic(0) To Logic(0)
Screen Close 1
Clip
End Proc
Procedure CREDITS
Get Cblock 1,85,35,164,133
Ink 0
Bar 85,37 To 235,167
Ink 1
Box 85,37 To 235,167
Ink 14
Box 86,38 To 234,166
Screen Copy 0,203,0,320,36 To 0,103,41
Ink 14,0 : Set Font _FONT
Text 115,88,"Programming"
Text 111,98,"And Graphics"
Ink 1
Text 114,110," D. Ramsey"
Ink 14,0
Text 114,126,"Game Design"
Ink 1,
Text 114,138," D. Ramsey"
Text 114,148," C. Ramsey"
Ink 7,
Text 94,162,"Click To Continue"
Screen Copy Logic To Physic
While Mouse Key<>1
Wend
Put Cblock 1 : Del Cblock
Screen Copy Logic To Physic
Wait Vbl
End Proc
Procedure CHECKWINNER
If SC(1)=0 or SC(2)=0 Then NDGAME : Pop Proc
End Proc
Procedure DEPRESS_SLIDERS
'
' Depress slide buttons
'
If MY=0
' left
Bob 2,(MX*20),MY*20+2,17 : Update
Wait 15
Bob Off 2 : Update : Wait Vbl
End If
'
'
If MY=9
' left
Bob 2,(MX*20),(MY*20),20 : Update
Wait 15
Bob Off 2 : Update : Wait Vbl
End If
'
'
If MX=9
' left
Bob 2,(MX*20),(MY*20),19 : Update
Wait 15
Bob Off 2 : Update : Wait Vbl
End If
'
'
If MX=0
' left
Bob 2,(MX*20)+2,(MY*20),18 : Update
Wait 15
Bob Off 2 : Update : Wait Vbl
End If
'
End Proc
Procedure NDGAME
'
' Display a simple Game Over message.
'
Ink 0
Bar 85,37 To 235,167
Ink 1
Box 85,37 To 235,167
Ink 14 : Set Font _FONT
Box 86,38 To 234,166
Screen Copy 0,203,0,320,36 To 0,103,41 : Ink 12,0
Text 120,100," Game Over"
Screen Copy Logic To Physic : Wait Vbl
'
' Do a very simple Anim.
'
Channel 1 To Bob 1 : Bob 1,330,100,1
If SC(1)=0 Then TEMP=1 : Anim 1,"(1,10)(11,10)L"
If SC(2)=0 Then TEMP=2 : Anim 1,"(2,10)(12,10)L"
' Who one?
If SC(1)=SC(2) Then Text 110,120," Match Drawn!" : Goto NND
Bob 1,155,110,TEMP : Anim On
Text 145,140,"Wins!"
'
' Copy to physical screen.
'
NND: Screen Copy Logic To Physic
'
' Play a simple sound effect
'
For TEMP=12 To 24
Play 3,TEMP,4
Play 12,TEMP+12,4
Next TEMP
For TEMP=1 To 5
Play 3,24,4
Play 12,36,4
Next TEMP
'
' Wait for mouse key
'
While Mouse Key=0 : Wend
'
' Set Game Over flag.
GAMEOVER=1
'
' Fade out game screen.
'
Fade 2,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778
Wait 30
'
End Proc
Procedure NW_GAME
'
' Display a `New Game?' requester.
'
' First get background as a compacted block.
'
Get Cblock 2,85,45,164,154
'
' Draw requester
'
Ink 0
Bar 85,45 To 235,165
Ink 1
Box 85,45 To 235,165
Ink 14,0 : Set Font _FONT
Box 86,46 To 234,164
Text 100,60,"Are you sure you"
Text 105,70," want to start"
Text 105,80," a new game?"
Locate 0,13
'
' The following few lines set 2 screen zones around the text. Zones number
' 5 and 6 are used so as not to affect existing zones 1-4.
'
Centre Border$(Zone$(" Yes Please ",5),2)
Locate 0,17
Centre Border$(Zone$("No, carry on",6),2)
'
' Copy requetser to physical screen.
'
Screen Copy Logic To Physic : Wait Vbl
'
' Wait for a selection.
'
Repeat
While Mouse Key<>1
Wend
M=Mouse Zone
Until M>4 and M<7
'
If M=5
' Set Quit flag
QUIT=1
Fade 2,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778
Wait 30
Else QUIT=0
End If
'
' Put the old background back. Delete the CBlock to save memory.
'
Put Cblock 2 : Del Cblock 2
'
' Copy to physical screen.
'
Screen Copy Logic To Physic : Wait Vbl
End Proc
Procedure INST
'
' This procedure shows the instruction screen, which is simply a packed
' IFF screen in bank 8.
'
' Unpack and hide instruction screen. Set all colours to grey.
Unpack 8 To 1 : Screen To Back 1
Palette $778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778
'
' Fade out game screen to the same colour grey
'
Screen 0
Fade 2,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778
Wait 30
'
' Bring instruction screen to front, and fade colours to sprite
' palette [ Fade 2 To -1 ].
'
Screen To Front 1
Screen 1
Fade 2 To -1
Wait 30
'
' Wait for user to hit left mouse button, then fade out instruction
' screen & close the screen.
'
While Mouse Key<>1 : Wend
Fade 2,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778
Wait 30
Screen Close 1
'
' Fade game screen back into view
'
Screen 0
Fade 2 To -1
Wait 30
End Proc
Procedure TITLE
'
' Unpack title screen & a spare screen with same dimensions
' and colours. Picture will copied bit by bit from the hidden screen
' into view.
'
Unpack 6 To 2 : Screen Hide 2
Unpack 6 To 0 : Cls 0 : Colour Back $778
Music 1 : Led Off : Tempo 28 : Mvolume 63
'
' Hide pointer
Hide On
'
' Set colour cycling of last 16 colours in palette.
'
Shift Up 1,16,31,1
'
For X=0 To 159 Step 20
For Y=0 To 200 Step 10
Wait Vbl
Screen Copy 2,X,Y,X+20,Y+10 To 0,X,Y
Screen Copy 2,300-X,Y,320-X,Y+10 To 0,300-X,Y
Next Y
Next X
'
' Close spare screen
'
Screen Close 2
'
' Set sprite as mouse pointer
'
' Set AMAL channel 1 to mouse pointer
Channel 1 To Sprite 1
ARROW$="L: Let X=XM ; Let Y=YM; Jump L"
Sprite 1,1,1,3 : Amal 1,ARROW$
'
' Switch on AMAL
'
Amal On
'
' Limit mouse to screen area
Wait Vbl : Limit Mouse X Hard(0),Y Hard(0) To X Hard(307),Y Hard(187)
'
' Set up screen zones for menu
'
Reserve Zone 4
Set Zone 1,86,67 To 239,89
Set Zone 2,86,92 To 239,114
Set Zone 3,86,117 To 239,139
Set Zone 4,86,142 To 239,164
'
' Wait for a selection
'
Repeat
While Mouse Key<>1 : Wend
MZ=Mouse Zone
Until MZ>0 and MZ<5
'
If MZ=1
' Demo mode
NUMPLAYERS=0
LEVEL=2
Else If MZ=2
' 2 players
NUMPLAYERS=2
Else
' 1 player, level 1 or 2
NUMPLAYERS=1
LEVEL=MZ-2
End If
End If
'
' Fade out title screen
'
Fade 2,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778,$778
For V=60 To 0 Step -2 : Mvolume V : Wait Vbl : Next V
'
' Close title screen
'
Screen Close 0
End Proc
'
' Move computation procedures
'
Procedure COMPUTE
'
' This is where the computer decides on it's move in a one player game.
' There are many ways you could do this in a board game, but in Quatro,
' the computer goes through every sqaure on the board, and checks for
' certain patterns of pieces. It then gives that square a `score'
' depending on how desirable it would be for the computer to move
' there. After it has been through every possible move, it simply looks
' for the move with the highest score, checks that it's a legal move,
' then makes it's move.
'
' Clear old values for best move
'
MX=0 : MY=0 : Rem These hold co-ords of move.
For X=0 To 9
For Y=0 To 9
BEST(X,Y)=0
OK(X,Y)=0
Next Y
Next X
'
' Go through each square on the board and give it a 'score'
' The computer will go for the square with the highest score. [BEST()]
'
For X=1 To 8
For Y=1 To 8
'
' Has player pressed a button ?
'
CHK_BUTTONS
If QUIT=1
Pop Proc
End If
'
' Check for various patterns of pieces
'
If(LEVEL=2) or(LEVEL=1 and Rnd(2)<2)
CHECKSQ[1,X,Y]
End If
CHECKSQ[2,X,Y]
CHKSINGLE[X,Y]
If LEVEL=2
CHK_ADVANCED[X,Y]
End If
Next Y
Next X
'
' SHW_BOARD
'
' Make the move. Best move position is returned in the variables MX and MY.
'
MAKEMOVE
'
' Just in case computer doesn't find a move (very rare), slide a column.
'
If MX=0 and MY=0
MX=5 : MY=9
End If
'
' Move Pointer to square
'
Amal Off
'
' Set External AMAL registers to X & Y co-ords of move.
'
Amreg(0)=X Hard((MX*20)+5)
Amreg(1)=Y Hard((MY*20)+5)
Amal 1,"Let R0=RA-XM ; Let R1=RB-YM ; Move R0,R1,20 ;"
Amal On 1
Wait 35
End Proc
Procedure CHECKSQ[P,PX,PY]
'
' Reset 2 temporary variables, then check two squares at position PX,PY
' to see if they are both red or green.
'
TEMP=0 : TEMP2=0
' Then check row below, to see if computer can form a square
CHKHORIZ[P,PX,PY]
TEMP=Param
CHKHORIZ[P,PX,PY+1]
TEMP2=Param
'
' Variables TEMP & TEMP2 contain 0,1,2 or 3 depending on how many pieces
' match then colour P. (P=1 for player 1, etc...)
'
' S=Score for forming a square.
'
' Higher for Player 1, as it is more important for computer to block
' opponents squares than make it's own.
'
S=8-(P*2)
If P=PLYR Then S2=-3 Else S2=5
'
If(TEMP=2) and(TEMP2=3)
If PX<8
Add BEST(PX+2,PY+1),4
End If
If PY<8
Add BEST(PX,PY+2),4
End If
Add BEST(PX,PY),S
Add BEST(9,PY),S2
Add BEST(0,PY+1),S2
Add BEST(PX,9),S2
Add BEST(PX+1,0),S2
End If
'
'
If(TEMP=1) and(TEMP2=3)
If PX>1
Add BEST(PX-1,PY),4
End If
If PY<8
Add BEST(PX+1,PY+2),4
End If
Add BEST(PX+1,PY),S
Add BEST(0,PY),S2
Add BEST(9,PY+1),S2
Add BEST(PX,0),S2
Add BEST(PX+1,9),S2
End If
'
'
If(TEMP=3) and(TEMP2=2)
If PY>1
Add BEST(PX,PY-1),4
End If
If PX<8
Add BEST(PX+2,PY+1),4
End If
Add BEST(PX,PY+1),S
Add BEST(0,PY),S2
Add BEST(9,PY+1),S2
Add BEST(PX,0),S2
Add BEST(PX+1,9),S2
End If
'
'
If(TEMP=3) and(TEMP2=1)
If PY>1
Add BEST(PX+1,PY-1),4
End If
If PX>1
Add BEST(PX-1,PY+1),4
End If
Add BEST(PX+1,PY+1),S
Add BEST(9,PY),S2
Add BEST(0,PY+1),S2
Add BEST(PX,9),S2
Add BEST(PX+1,0),S2
End If
'
'
' If computer has only two pices in a row, increase score for that
' square by a smaller amount. This way, the computer will choose the
' best move possible.
'
If TEMP=3 and TEMP2=0
' Increase score of 2 squares below
Add BEST(PX,PY+1),2
Add BEST(PX+1,PY+1),2
' Increase score of 2 squares above
Add BEST(PX,PY-1),2
Add BEST(PX+1,PY-1),2
End If
'
' Computer has two pieces vertically
'
If TEMP=1 and TEMP2=1
' Increase score of 2 sqaures to right
Add BEST(PX+1,PY),2
Add BEST(PX+1,PY+1),2
' Increase score of 2 sqaures to left
Add BEST(PX-1,PY),2
Add BEST(PX-1,PY+1),2
End If
'
' Pieces in a OO or OO shape
' OO OO
'
' computer should slide row PY to the left or right
'
' Slide row one way for player 1's pieces, the opposite way for computer's.
'
S=1+(NUMPLAYERS*6)
'
If TEMP=3 and PX<8
' Check if computer can make a square
CHKHORIZ[P,PX+1,PY+1] : TEMP=Param
If TEMP=3
If P=PLYR
Add BEST(9,PY),S
Add BEST(0,PY+1),S
Else
Add BEST(0,PY),S
Add BEST(9,PY+1),S
End If
End If
CHKHORIZ[P,PX-1,PY+1] : TEMP=Param
If TEMP=3
If P=PLYR
Add BEST(0,PY),S
Else
Add BEST(9,PY),S
End If
End If
'
End If
'
If LEVEL=2
' Check for O O
' OO and OO shapes.
' O O
'
CHKVERT[P,PX,PY] : TEMP=Param
If TEMP=3 and PY<8
'
CHKVERT[P,PX+1,PY+1] : TEMP=Param
If TEMP=3
If P=PLYR
Add BEST(PX,9),S
Else
Add BEST(PX,0),S
End If
End If
CHKVERT[P,PX-1,PY+1] : TEMP=Param
If TEMP=3
If P=PLYR
Add BEST(PX,9),S
Else
Add BEST(PX,0),S
End If
End If
'
End If
End If
End Proc
Procedure CHKHORIZ[P,PX,PY]
CHECK=0
If PY>8 Then Pop Proc
If BD(PX,PY)=P
Inc CHECK
End If
'
' If end of board is reached, check the piece at the beginning of the row,
' as these pieces are effectively next to each other.
'
If PX<8
If BD(PX+1,PY)=P
Add CHECK,2
End If
Else
If BD(1,PY)=P
Add CHECK,2
End If
End If
'Return a param of 1,2 or 3 depending on how many pieces match p
End Proc[CHECK]
Procedure CHKVERT[P,PX,PY]
CHECK=0
' If PY<8
If BD(PX,PY)=P
Inc CHECK
End If
' End If
'
' If end of board is reached, check the piece at the beginning of the row,
' as these pieces are effectively next to each other.
'
If PY<8
If BD(PX,PY+1)=P
Add CHECK,2
End If
Else
If BD(PX,1)=P
Add CHECK,2
End If
End If
'Return a param of 1,2 or 3 depending on how many pieces match p
End Proc[CHECK]
Procedure CHKSINGLE[PX,PY]
If PX>1
If BD(PX-1,PY)=PLYR
Inc BEST(PX,PY)
OK(PX,PY)=1
End If
End If
'
If PY>1
If BD(PX,PY-1)=PLYR
Inc BEST(PX,PY)
OK(PX,PY)=1
End If
End If
'
If PX<8
If BD(PX+1,PY)=PLYR
Inc BEST(PX,PY)
OK(PX,PY)=1
End If
End If
'
If PY<8
If BD(PX,PY+1)=PLYR
Inc BEST(PX,PY)
OK(PX,PY)=1
End If
End If
'
End Proc
Procedure MAKEMOVE
'
' In this procedure, the computer will find it's best move, and set
' the variables MX and MY to the co-ordinates of that move.
'
THINK:
BEST=0
For X=0 To 9
For Y=0 To 9
If BEST(X,Y)>BEST
If BD(X,Y)<1 or BD(X,Y)>2
'
If X>0 and X<9 and Y>0 and Y<9
If OK(X,Y)=1
' Best move so far
BEST=BEST(X,Y)
MX=X
MY=Y
End If
Else
'A sliding move
If(X=Y) or(X=0 and Y=9) or(X=9 and Y=0)
' Can't go in the corners, as it's not possible to
' slide a row and a column
' at the same time.
Else
BEST=BEST(X,Y)
MX=X
MY=Y
End If
End If
End If
End If
Next Y
Next X
'
' Has computer made same move again?
'
If OMX(PLYR)=MX and OMY(PLYR)=MY
' Increase counter. Computer should not make the same move
' three times in a row
Inc COUNT
Else
COUNT=0
End If
'
' Computer is more persistent on higher level
'
If COUNT=LEVEL
BEST(MX,MY)=0
COUNT=0
Goto THINK
End If
'
'
' Randomize movement in Demo Mode and easy level.
'
If(NUMPLAYERS=0) or(LEVEL=1)
If((MX=0 or MX=9) and MY=8 and Rnd(1)=0)
BEST(MX,MY)=1
COUNT=0
Goto THINK
End If
End If
'
' Store computer's last move
'
OMX(PLYR)=MX
OMY(PLYR)=MY
End Proc
Procedure SHW_BOARD
'
' This is a small procedure I wrote, to see where the computer thought
' the best moves were. It is not actually used in the game, but you can
' see what it does if you remove the apostrophe (') from the line
'
' ' SHW_BOARD
'
' in the COMPUTE procedure.
'
' When you play the game, the `score' given to each square will be
' displayed at the top of the screen before the computer makes it's move.
' The higher the number, the more the computer wants to make a particular
' move. No account is taken of whether or not a particular move is
' legal, as this is done in the MAKEMOVE procedure.
'
Locate 0,0
For Y=0 To 9
For X=0 To 9
Print BEST(X,Y);
Next X
Print
Next Y
End Proc
Procedure CHK_ADVANCED[PX,PY]
'
' This procedure is only called on level 3, the hard level. It checks for
' more advanced patterns that might enable the computer to form a square
' in two moves time. This will be the only time when the computer `thinks
' ahead'.
'
' These are the patterns of pieces on the board that the computer will
' search for : -
' 1 2 3 4
' OO OO O O
' OO OO O O
' O O
' O O
'
' This should be enough to make the computer a pretty good player.
' Remember, the computer will not `miss' any patterns as a human player
' might.
' If you want, you can add more search patterns at the end of this
' procedure.
'
TEMP=0 : TEMP2=0
'
' Pattern 1
'
CHKHORIZ[PLYR,PX,PY]
TEMP=Param
If PX<7
CHKHORIZ[PLYR,PX+2,PY+1]
TEMP2=Param
End If
'
If TEMP=3 and TEMP2=3
Add BEST(9,PY),3
Add BEST(0,PY+1),3
End If
'
' Pattern 2
'
If PX>1
CHKHORIZ[PLYR,PX-2,PY+1]
TEMP2=Param
If TEMP=3 and TEMP2=3
Add BEST(0,PY),3
Add BEST(9,PY+1),3
End If
End If
TEMP=0 : TEMP2=0
'
' Pattern 3
'
CHKVERT[PLYR,PX,PY]
TEMP=Param
If PY<7
CHKVERT[PLYR,PX+1,PY+2]
TEMP2=Param
End If
'
If TEMP=3 and TEMP2=3
Add BEST(PX,9),3
Add BEST(PX+1,0),3
End If
'
' Pattern 4
'
If PY>1
CHKVERT[PLYR,PX+1,PY-2]
TEMP2=Param
If TEMP=3 and TEMP2=3
Add BEST(PX,0),3
Add BEST(PX+1,9),3
End If
End If
'
End Proc